package com.mchsdk.paysdk.http.process;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.entity.StringEntity;

import com.lidroid.xutils.http.RequestParams;
import com.mchsdk.open.ApiCallback;
import com.mchsdk.paysdk.bean.ChannelAndGameInfo;
import com.mchsdk.paysdk.bean.PersonalCenterModel;
import com.mchsdk.paysdk.config.MCHConstant;
import com.mchsdk.paysdk.http.request.ZFBOrderInfoRequest;
import com.mchsdk.paysdk.utils.MCLog;
import com.mchsdk.paysdk.utils.RequestParamUtil;

import android.os.Handler;
import android.text.TextUtils;

public class ZFBOrderInfoProcess {

	private static final String TAG = "ZfbOrderInfoProcess";

	/**
	 * 商品名称
	 */
	private String goodsName;

	/**
	 * 商品价格
	 */
	private String goodsPrice;

	/**
	 * 商品描述
	 */
	private String goodsDesc;

	/**
	 * 充值类型 平台币 0 游戏 1
	 */
	private String payType;
	/**
	 * 充值类型 平台币 0 游戏 1
	 */

	/**
	 * 游戏订单信息
	 */
	private String extend;
	public ZFBOrderInfoProcess() {
	}

	public void setExtend(String extend) {
		this.extend = extend;
	}

	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}

	public void setGoodsPrice(String goodsPrice) {
		this.goodsPrice = goodsPrice;
	}

	public void setGoodsDesc(String goodsDesc) {
		this.goodsDesc = goodsDesc;
	}

	private String serverName;
	private String roleName;

	public void setServerName(String serverName) {
		this.serverName = serverName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public void post(Handler handler) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("sdk_version", "0");//表示android发送的请求，固定值0
		map.put("title", goodsName);
		map.put("price", goodsPrice);
		map.put("body", goodsDesc);
		
//		map.put("game_serverid",ApiCallback.order().getGameServerId());
		
		map.put("game_id", ChannelAndGameInfo.getInstance().getGameId());
		map.put("game_name", ChannelAndGameInfo.getInstance().getGameName());
		map.put("game_appid", ChannelAndGameInfo.getInstance().getGameAppId());
//		map.put("promote_id", MCHConstant.getInstance().getPromoteId());
//		map.put("promote_account", MCHConstant.getInstance().getPromoteAccount());
		map.put("code", payType);
		map.put("account", PersonalCenterModel.getInstance().getAccount());
		map.put("user_id", PersonalCenterModel.getInstance().getUserId());
		map.put("extend", extend);
		map.put("is_uc",PersonalCenterModel.getInstance().getIs_uc());

		if (!TextUtils.isEmpty(serverName) && !TextUtils.isEmpty(roleName) && payType.equals("1")) {
			map.put("server_name", serverName);
			map.put("game_player_name", roleName);
		}
		String param = RequestParamUtil.getRequestParamString(map);
		RequestParams params = new RequestParams();
		MCLog.e(TAG, "fun#post postSign:" + map.toString());
		try {
			params.setBodyEntity(new StringEntity(param.toString()));
		} catch (UnsupportedEncodingException e) {
			params = null;
			MCLog.e(TAG, "fun#post UnsupportedEncodingException:" + e);
		}
		if (null != handler && null != params) {
			ZFBOrderInfoRequest zfbPayRequest = new ZFBOrderInfoRequest(handler);
			zfbPayRequest.post(MCHConstant.getInstance().getZfbVerificationOrderUrl(), params);
		} else {
			MCLog.e(TAG, "fun#post handler is null or url is null");
		}
	}

	public void setPayType(String payType) {
		this.payType = payType;
	}
}
